{php $bootstrap_type = 3;}
{template 'header'}
{template 'common'}
<script type="text/javascript" src="../addons/eso_sale/images/jquery.gcjs.js"></script>
<link type="text/css" rel="stylesheet" href="../addons/eso_sale/images/style.css">
<link href="../addons/eso_sale/recouse/css/xin_v3.s.min.css" rel="stylesheet" type="text/css" />

<style>
    .shopcart-footer{margin-bottom:30px;}
</style>
<div class="head">
    <a href="javascript:history.back();" class="bn pull-left"><i class="fa fa-angle-left"></i></a>
    <span class="title">购物车</span>
    <a href="javascript:void(0)" onclick="clearCart()" class="bn pull-right" style="font-size:18px;"><i class="fa fa-trash"></i> 清空</a>
</div>
<div class="shopcart-main img-rounded" style="margin-top:50px">
    <!--	<div class="shopcart-hd">
            <span class="pull-left">{if empty($_W['account']['name'])}易志科技团队{else}{$_W['account']['name']}{/if}»</span>
            <a class="pull-right icon-remove-sign" href="{php echo $this->mturl('clear');}" onclick="return confirm('此操作不可恢复，确认？'); return false;"></a>
        </div>-->
    <div style='text-align:center;padding:50px 0 50px 0; {if count($list)>0}display:none{/if}' id='cartempty'>
        <img src='../addons/eso_sale/images/icon_cart_empty.png' /><br/><br/>
        <span style='color:#adadad'>您的购物车空空如也，赶紧去选购吧~~</span>
    </div>

    {loop $list $item}
    {php $price += $item['totalprice'];}

    {php $goods = $item['goods']}
    <span id="stock_{$item['id']}" style='display:none'>{$goods['total']}</span>
    <div class="shopcart-item clearfix" id='item_{$item['id']}' style='height:{if !empty($goods['optionname'])}140px;{else}120px{/if}'>
        <img src="{$_W['attachurl']}{$goods['thumb']}">
        <div class="shopcart-item-detail">
            <div class="name">{$goods['title']}{if $goods['unit']}{/if}</div>
            {if !empty($goods['optionname'])}<div class="price">规格：<span>{$goods['optionname']}</span></div>{/if}

            <div class="price">单价：<span id="singleprice_{$item['id']}">{$goods['marketprice']}</span> 元{if !empty($goods['unit'])} / {$goods['unit']}{/if}</div>
            <div class="price">小计：<span class='singletotalprice' id="goodsprice_{$item['id']}">{$item['totalprice']}</span> 元</div>
            <div class="input-group">
                    <span class="input-group-btn">
                        <button class="btn btn-default btn-sm" type="button" onclick="reduceNum({$item['id']})"><i class="fa fa-minus"></i></button>
                    </span>
                <input type="tel" class="form-control input-sm pricetotal goodsnum" value="{$item['total']}" price="{$goods['marketprice']}" pricetotal="{$item['totalprice']}" id="goodsnum_{$item['id']}" cartid='{$item['id']}' maxbuy="{$goods['maxbuy']}" />
                    <span class="input-group-btn">
                        <button class="btn btn-default btn-sm" type="button" onclick="addNum({$item['id']},{$goods['maxbuy']})"><i class="fa fa-plus"></i></button>
                    </span>
            </div>
        </div>
        <a href="javascript:;" onclick="removeCart({$item['id']})" class="shopcart-item-remove"><i class="icon-remove"></i> 删除</a>
    </div>

{php $n++;}
{/loop}
</div>
<div id='cartfooter' class="shopcart-footer" {if count($list)<=0}style='display:none'{else} style='margin-bottom: 12px;'  {/if}'>
<span class="pull-left">合计：<span id="pricetotal">{$price}</span> 元</span>
<a href="{php echo $this->mturl('confirm')}" class="btn btn-success pull-right">立即结算</a>
</div>
</div>


<script type="text/javascript">
    $(function(){
        $(".goodsnum").blur(function(){
            var id = $(this).attr("cartid");
            if($(this).isInt()){
                var num = parseInt( $("#goodsnum_" + id).val() );
                var maxbuy = parseInt( $(this).attr("maxbuy") );
                var mb = maxbuy;
                var stock =$("#stock_" + id).html()==''?-1:parseInt($("#stock_" + id).html());
                if(mb>stock && stock!=-1){
                    mb = stock;
                }

                if(num>mb && mb>0){
                    tip("最多只能购买 " + mb + " 件!",true);
                    $("#goodsnum_" + id).val(mb);
                    return;
                }
                updateCart(id,num);
            }
            else{
                $(this).val("1");
                updateCart(id,1);
            }

        })

    })
    function clearCart(){
        if (confirm('确定要清空购物车吗？')) {
            tip("正在处理数据...");
            $.getJSON('{php echo $this->mturl('mycart',array('op'=>'clear'));}', function(s){
                $(".shopcart-item").remove();
                $("#cartempty").show();
                $("#cartfooter").hide();
                tip_close();
            });
        }
    }
    function removeCart(id){
        if (confirm('您确定要删除此商品吗？')) {
            tip("正在处理数据...");
            var url  = '{php echo $this->mturl('mycart', array('op'=>'remove'))}' + "&id=" + id;
            $.getJSON(url, function(s){
                $("#item_" + s.cartid).remove();
                if($(".shopcart-item").length<=0){
                    $("#cartempty").show();
                    $("#cartfooter").hide();
                }
                tip_close();
                canculate();
            });
        }
    }
    function updateCart(id,num){

        var url  = '{php echo $this->mturl('mycart', array('op'=>'update'))}' + "&id=" + id+"&num=" + num;
        $.getJSON(url, function(s){

        });
    }
    function checkMaxBuy(id, maxbuy){


    }
    function addNum(id,maxbuy){
        var mb = maxbuy;
        var stock =$("#stock_" + id).html()==''?-1:parseInt($("#stock_" + id).html());
        if(mb>stock && stock!=-1){
            mb = stock;
        }

        var num = parseInt( $("#goodsnum_" + id).val() ) + 1;
        if(num>mb && mb>0){
            tip("最多只能购买 " + mb + " 件!",true);
            return;
        }
        $("#goodsnum_" + id).val(num);
        var price = parseFloat( $("#singleprice_"+id).html() ) * num;
        $("#goodsprice_" + id).html(price);
        canculate();
        updateCart(id,num);
    }
    function reduceNum(id){
        var num = parseInt( $("#goodsnum_" + id).val() );
        if(num-1<=0){
            return;
        }
        num--;
        $("#goodsnum_" + id).val(num);
        var price = parseFloat( $("#singleprice_"+id).html() ) * num;
        $("#goodsprice_" + id).html(price);
        canculate();
        updateCart(id,num);
    }
    function canculate(){
        var total = 0;
        $(".singletotalprice").each(function(){

            total+=parseFloat( $(this).html() );
        });

        $("#pricetotal").html(total);
    }
</script>


<div class="wx_nav"><a href="{php echo $this->mturl('list')}" data-href="###" ptag="37080.1.1" class="nav_index on">首页</a><a href="{php echo $this->mturl('listCategory')}"  ptag="37080.1.2" class="nav_search" style="display:">分类</a><a href="{php echo $this->mturl('mycart')}"  ptag="37080.1.3" class="nav_shopcart">购物车</a><a href="{php echo $this->mturl('myorder')}"  ptag="37080.1.4" class="nav_me">我的订单</a><a href="{$ydyy}"  ptag="37080.1.4" class="nav_fav">一键关注</a></div>

<script src="../addons/eso_sale/recouse/js/zepto.min.js" type="text/javascript"></script>

<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript">
    //获取指定cookes函数
    function getCookie(name)
    {
        var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");

        if(arr=document.cookie.match(reg))

            return unescape(arr[2]);
        else
            return null;
    }

    if(navigator.appName == 'Microsoft Internet Explorer'){
        if(navigator.userAgent.indexOf("MSIE 5.0")>0 || navigator.userAgent.indexOf("MSIE 6.0")>0 || navigator.userAgent.indexOf("MSIE 7.0")>0) {
            alert('您使用的 IE 浏览器版本过低, 推荐使用 Chrome 浏览器或 IE8 及以上版本浏览器.');
        }
    }

    // jssdk config 对象
    jssdkconfig = {php echo json_encode($_W['account']['jssdkconfig']);} || {};
    // 是否启用调试
    jssdkconfig.debug = false;
    //
    jssdkconfig.jsApiList = [
        'checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideMenuItems',
        'showMenuItems',
        'hideAllNonBaseMenuItem',
        'showAllNonBaseMenuItem',
        'translateVoice',
        'startRecord',
        'stopRecord',
        'onRecordEnd',
        'playVoice',
        'pauseVoice',
        'stopVoice',
        'uploadVoice',
        'downloadVoice',
        'chooseImage',
        'previewImage',
        'uploadImage',
        'downloadImage',
        'getNetworkType',
        'openLocation',
        'getLocation',
        'hideOptionMenu',
        'showOptionMenu',
        'closeWindow',
        'scanQRCode',
        'chooseWXPay',
        'openProductSpecificView',
        'addCard',
        'chooseCard',
        'openCard'
    ];

    var wxData = {
        //     "appId": "{$_W['account']['key']}",
        "imgUrl" : '{$_W['siteroot']}/source/modules/eso_sale/icon.jpg',
        "link" : '{php echo $_W['siteroot']."app/".$this->mturl('list',array('id'=>$id))}&mid='+getCookie("mid"),
        "desc" : '看你能捞多少佣金',
        "title" : '{$_W['account']['name']}'
    };

    wx.config(jssdkconfig);
    wx.ready(function () {
        wx.onMenuShareAppMessage(wxData);
        wx.onMenuShareTimeline(wxData);
        wx.onMenuShareQQ(wxData);
        wx.onMenuShareWeibo(wxData);
    });
</script>

</body>
</html>